package com.wc.dao.impl;

import com.wc.constant.BMS;
import com.wc.dao.BookDao;
import com.wc.domain.Book;
import com.wc.utils.FileUtil;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl implements BookDao {

    @Override
    public List<Book> selectAllBook() {
        List<Book> res = new ArrayList<>();
        try(BufferedReader br = new BufferedReader(new FileReader(BMS.DB_BOOKS));){
            String line = null;
            while((line = br.readLine())!=null){
                Book book = FileUtil.str2Book(line);
                res.add(book);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }
}
